<template>
	<div class="app-container bg-#fff">
		<div class="search-form">
			<el-form ref="queryForm" :model="query" :inline="true" label-width="160px">
				<el-row class="flex flex-wrap">
					<el-col :span="6">
						<el-form-item label="审核编号" prop="auditCode">
							<el-input v-model="query.auditCode" placeholder="请输入审核编号" clearable />
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="资料类型" prop="dataCategory">
							<el-select multiple clearable v-model="query.dataCategory" placeholder="请选择">
								<el-option v-for="item in dataTypeList" :key="item.value" :label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="审核状态" prop="status">
							<el-select multiple clearable v-model="query.status" placeholder="请选择">
								<el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="打款方式" prop="paymentType">
							<el-select multiple clearable v-model="query.paymentType" placeholder="请选择">
								<el-option v-for="item in paymentTypeList" :key="item.value" :label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="新车车架号" prop="vinNumber">
							<el-input v-model="query.vinNumber" placeholder="请输入新车车架号" clearable />
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="车主姓名" prop="carOwnerName">
							<el-input v-model="query.carOwnerName" placeholder="请输入车主姓名" clearable />
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="是否上传过凭证" prop="isUploadVoucher">
							<el-select clearable multiple v-model="query.isUploadVoucher" placeholder="请选择">
								<el-option label="是" :value="1"></el-option>
								<el-option label="否" :value="0"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="最新变更时间" prop="submitBeginTime">
							<div class="flex">
								<el-date-picker class="flex-1" clearable v-model="query.lastChangeTimeBeginTime"
									value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange(1, 'lastChangeTimeBeginTime', $event)"
									placeholder="开始日期"></el-date-picker>
								<span class="mx-10px">-</span>
								<el-date-picker class="flex-1" clearable v-model="query.lastChangeTimeEndTime"
									value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange(2, 'lastChangeTimeEndTime', $event)"
									placeholder="结束日期"></el-date-picker>
							</div>
						</el-form-item>
					</el-col>

					<el-col :span="8">
						<el-form-item label="创建时间" prop="beginTime">
							<div class="flex">
								<el-date-picker class="flex-1" clearable v-model="query.beginTime" value-format="yyyy-MM-dd HH:mm:ss"
									@change="timeChange(1, 'beginTime', $event)" placeholder="开始日期"></el-date-picker>
								<span class="mx-10px">-</span>
								<el-date-picker class="flex-1" clearable v-model="query.endTime" value-format="yyyy-MM-dd HH:mm:ss"
									@change="timeChange(2, 'endTime', $event)" placeholder="结束日期"></el-date-picker>
							</div>
						</el-form-item>
					</el-col>

					<el-col :span="8">
						<el-form-item label="凭证初次提交时间" prop="voucherTimeBeginTime">
							<div class="flex">
								<el-date-picker class="flex-1" clearable v-model="query.voucherTimeBeginTime"
									value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange(1, 'voucherTimeBeginTime', $event)"
									placeholder="开始日期"></el-date-picker>
								<span class="mx-10px">-</span>
								<el-date-picker class="flex-1" clearable v-model="query.voucherTimeEndTime"
									value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange(2, 'voucherTimeEndTime', $event)"
									placeholder="结束日期"></el-date-picker>
							</div>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="最后一次凭证提交时间" prop="lastVoucherTimeBeginTime">
							<div class="flex">
								<el-date-picker class="flex-1" clearable v-model="query.lastVoucherTimeBeginTime"
									value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange(1, 'lastVoucherTimeBeginTime', $event)"
									placeholder="开始日期"></el-date-picker>
								<span class="mx-10px">-</span>
								<el-date-picker class="flex-1" clearable v-model="query.lastVoucherTimeEndTime"
									value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange(2, 'lastVoucherTimeEndTime', $event)"
									placeholder="结束日期"></el-date-picker>
							</div>
						</el-form-item>
					</el-col>

					<el-col :span="8">
						<el-form-item label="审核通过时间" prop="lastExaminePassTimeBeginTime">
							<div class="flex">
								<el-date-picker class="flex-1" clearable v-model="query.lastExaminePassTimeBeginTime"
									value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange(1, 'lastExaminePassTimeBeginTime', $event)"
									placeholder="开始日期"></el-date-picker>
								<span class="mx-10px">-</span>
								<el-date-picker class="flex-1" clearable v-model="query.lastExaminePassTimeEndTime"
									value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange(2, 'lastExaminePassTimeEndTime', $event)"
									placeholder="结束日期"></el-date-picker>
							</div>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="反馈截止时间" prop="feedbackDeadlineBeginTime">
							<div class="flex">
								<el-date-picker class="flex-1" clearable v-model="query.feedbackDeadlineBeginTime"
									value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange(1, 'feedbackDeadlineBeginTime', $event)"
									placeholder="开始日期"></el-date-picker>
								<span class="mx-10px">-</span>
								<el-date-picker class="flex-1" clearable v-model="query.feedbackDeadlineEndTime"
									value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange(2, 'feedbackDeadlineEndTime', $event)"
									placeholder="结束日期"></el-date-picker>
							</div>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="兑现日期" prop="exchangeBeginTime">
							<div class="flex">
								<el-date-picker class="flex-1" clearable v-model="query.exchangeBeginTime"
									value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange(1, 'exchangeBeginTime', $event)"
									placeholder="开始日期"></el-date-picker>
								<span class="mx-10px">-</span>
								<el-date-picker class="flex-1" clearable v-model="query.exchangeEndTime"
									value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange(2, 'exchangeEndTime', $event)"
									placeholder="结束日期"></el-date-picker>
							</div>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item>
							<div class="flex items-center justify-between">
								<div>
									<el-button class="ml-20px" type="primary" icon="el-icon-search" @click="handleQuery">搜索
									</el-button>
									<el-button icon="el-icon-refresh" @click="resetQuery">重置
									</el-button>
								</div>
							</div>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</div>
		<div class="mb-10px">
			<export-button text="导出列表" title="置换兑换审核记录" url="/api/v1/dataauditExchange/export" :formData="false" :obj="{
				...query,
			}" />

			<export-button text="导出明细" title="置换兑换审核明细记录" url="/api/v1/dataauditExchange/exportDetail" :formData="false" :obj="{
				...query,
			}" />
		</div>
		<div class="text-left text-#F80D0D mb-10px font-500 text-15px">
			<span>兑现金额：若 “值” 为空，表明数据处于初始化状态；若 “值” 大于 0，意味着返利成功；若 “值” 小于 0，则表示返利失败/扣除返利 。</span>
		</div>
		<div class="wrapper-container">
			<el-table v-loading="loading" :data="tableData" stripe border>
				<el-table-column label="审核编号" align="center" prop="dataaudit.auditCode" width="180">
					<template #default="{ row }">
						<!-- 当审核状态为待上传凭证且当前日期距离反馈截止时间不足N天时 -->
						<div style="position: absolute;left: 0;top: 5px;"
							v-if="row.status == 2 && compareDateDifference(row.feedbackDeadlineTime, currentTime, dictValue)">
							<el-tag type="danger">！待上传</el-tag>
						</div>
						{{ row.dataaudit.auditCode }}
					</template>
				</el-table-column>
				<el-table-column label="审核状态" align="center" prop="status" width="180">
					<template #default="{ row }">
						<el-tag v-if="row.status == 1">待兑现</el-tag>
						<el-tag type="warning" v-if="row.status == 2">待上传凭证</el-tag>
						<el-tag type="info" v-if="row.status == 3">待审核</el-tag>
						<el-tag type="danger" v-if="row.status == 4">驳回待提交</el-tag>
						<el-tag type="success" v-if="row.status == 5">审核通过</el-tag>
						<el-tag type="danger" v-if="row.status == 6">已作废</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="4S店" align="center" prop="dataaudit.ownerName" width="180" />
				<el-table-column label="4S店所在省份" align="center" prop="dataaudit.province" width="180" />
				<el-table-column label="4S店所城市" align="center" prop="dataaudit.city" width="180" />
				<el-table-column label="ERP编码" align="center" prop="dataaudit.erpCode" width="180" />
				<el-table-column label="本店经营品牌" align="center" prop="dataaudit.manufactureName" width="180" />
				<el-table-column label="车主姓名" align="center" prop="paymentType" width="180">
					<template #default="{ row }">
						{{ row.dataaudit ? row.dataaudit.carOwnerName : '--' }}
					</template>
				</el-table-column>
				<el-table-column label="所属大区" align="center" prop="dataaudit.region" width="180" />
				<el-table-column label="资料类型" align="center" prop="dataaudit.dataCategory" width="180">
					<template #default="{ row }">
						<div v-if="row.dataaudit.dataCategory == -1">换购</div>
						<div v-if="row.dataaudit.dataCategory == -2">增购</div>
						<div v-if="row.dataaudit.dataCategory == -3">报废</div>
					</template>
				</el-table-column>
				<el-table-column label="新车车架号" align="center" prop="dataaudit.vinNumber" width="180" />
				<el-table-column label="打款方式" align="center" prop="paymentType" width="180">
					<template #default="{ row }">
						<span v-if="row.paymentType == 1">银行转账</span>
						<span v-else-if="row.paymentType == 2">抵扣车款</span>
						<span v-else-if="row.paymentType == 3">其他</span>
						<span v-else>--</span>
					</template>
				</el-table-column>
				<el-table-column label="兑现金额" align="center" prop="exchangeAmount" width="180" />
				<el-table-column label="创建时间" align="center" width="180" :formatter="(row) => row.createTime || '--'">
				</el-table-column>
				<el-table-column label="最新变更时间" align="center" width="180" :formatter="(row) => row.lastChangeTime || '--'">
				</el-table-column>
				<el-table-column label="凭证初次提交时间" align="center" width="180" :formatter="(row) => row.voucherTime || '--'">
				</el-table-column>
				<el-table-column label="最后一次凭证提交时间" align="center" width="180"
					:formatter="(row) => row.lastVoucherTime || '--'">
				</el-table-column>
				<el-table-column label="审核通过时间" align="center" width="180"
					:formatter="(row) => row.lastExaminePassTime || '--'">
				</el-table-column>
				<el-table-column label="操作" align="center" fixed="right" width="180">
					<template #default="{ row }">
						<el-button type="text" @click="handleCheckDetail(row)">详情
						</el-button>
						<el-button type="text" @click="$refs.log.init(row)">操作日志
						</el-button>
						<el-button v-if="row.status == 2" type="text" @click="handleUpload(row)">上传凭证
						</el-button>
						<el-button v-if="row.status == 4" type="text" @click="handleReUpload(row)">重新上传凭证
						</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="text-right">
				<pagination :total="total" layout="slot,sizes, prev,next" :page.sync="query.pageNum"
					:limit.sync="query.pageSize" @pagination="getList">
					<span class="font-400" v-if="total >= 0">共{{ total }}行</span>
					<!-- <el-button :loading="totalLoading" @click="getListCount" v-else>显示行数
					</el-button> -->
				</pagination>
			</div>
		</div>
		<Log ref="log" />
	</div>
</template>

<script>
import Log from "./components/log.vue";

import {
	manufacturerBrandList,
	getvdataaudiexchangelist,
	getLog,//日志
	getData,
	dictOne
} from "@/api/exchangeAndRedemption/index"

import { hybridEncrypt } from "@/utils/crypto"

export default {
	name: "Data-audition",
	components: {
		Log
	},
	data() {
		return {
			showErr: false,
			loading: false,
			totalLoading: false,
			isSearch: false,
			// 表格数据
			tableData: [],
			submitTime: [],
			lastSubmitTime: [],
			lastTrialPassTime: [],
			total: -1,
			// 表单参数
			query: {
				auditCode: "",//审核编码
				manufactureId: [],//厂商品牌id
				dataCategory: [],//资料类型
				// auditStatus: [],//资料审核状态	
				status: [],//兑换审核状态
				// region: [],//所属大区
				// financecompanyId: [],//4s店
				// province: "",
				// city: "",
				// erpCode: "",
				vinNumber: "",
				carOwnerName: "",
				paymentType: [],//打款方式：1银行转账 2抵扣车款 3其他
				lastChangeTimeBeginTime: "",	//最新变更时间---开始时间
				lastChangeTimeEndTime: "",//最新变更时间---结束时间
				beginTime: "",//开始时间
				endTime: "",//结束时间
				voucherTimeBeginTime: "",//凭证提交时间-开始时间
				voucherTimeEndTime: "",//凭证提交时间-结束时间
				lastVoucherTimeBeginTime: "",//最后一次凭证提交时间-开始时间
				lastVoucherTimeEndTime: "",//最后一次凭证提交时间-结束时间
				isUploadVoucher: [],//是否上传凭证
				lastExaminePassTimeBeginTime: "",//最后一次审核通过时间-开始时间
				lastExaminePassTimeEndTime: "",//最后一次审核通过时间-结束时间
				exchangeBeginTime: "",
				exchangeEndTime: "",
				pageNum: 1,
				pageSize: 10,
			},
			// 审核状态列表
			statusList: [
				{
					label: "待兑现",
					value: 1
				},
				{
					label: "待上传凭证",
					value: 2
				},
				{
					label: "待审核",
					value: 3
				},
				{
					label: "驳回待提交",
					value: 4
				},
				{
					label: "审核通过",
					value: 5
				},
				{
					label: "已作废",
					value: 6
				},
			],
			//资料类型
			dataTypeList: [
				{
					label: "换购",
					value: -1
				},
				{
					label: "增购",
					value: -2
				}, {
					label: "报废",
					value: -3
				}
			],
			// 4s店列表
			storeOptions: [],
			//打款方式：1银行转账 2抵扣车款 3其他
			paymentTypeList: [{
				label: "银行转账",
				value: 1
			},
			{
				label: "抵扣车款",
				value: 2
			}, {
				label: "其他",
				value: 3
			}],
			// 厂商品牌列表
			manufacturerBrandOptions: [],
			// 厂商所属大区列表
			regionOptions: [],
			// 品牌列表
			brandOptions: [],
			//省份列表
			provinceOptions: [],
			//城市列表
			cityOptions: [],
			//数据来源
			sourceOptions: [
				{
					lable: "本系统",
					value: "00",
				},
				{
					lable: "老系统",
					value: "01",
				},
				{
					lable: "捷途",
					value: "02",
				},
			],
			// 合并数据来源
			mergeSourceOptions: [
				{
					lable: "全部",
					value: "",
				},
				{
					lable: "星纪元",
					value: "01",
				},
				{
					lable: "其他",
					value: "00",
				},
			],
			importDataAuditShow: false,//导入置换数据弹框
			importRebateDataShow: false,//导入返利数据弹框
			fileType: ["xlsx"],
			fileList: [],
			fileListRebateData: [],
			uploadMsg: "",
			btnloading: false,
			btn: "确  认",
			dictValue: 0,
			currentTime: 0
		};
	},
	watch: {
		$route: {
			handler(newVal) {
				const query = newVal.query;
				console.log("query", query);
				// let value = hybridEncrypt(JSON.stringify({
				// 	"key": "mifeng_jiecheng@r86xlsthhf3l4jm6gjx0zizs",
				// 	...query
				// }))
				// window.localStorage.setItem("query", JSON.stringify(query))
				// window.localStorage.setItem("user", JSON.stringify(value))
			},
			immediate: true,
			deep: true,
		},
	},
	created() {

	},
	beforeDestroy() {

	},
	async mounted() {
		const queryParams = this.$cache.session.getJSON("data-exchangeAndRedemption-query");
		if (queryParams) {
			this.query = queryParams;
			console.log(Object.keys(queryParams));
			for (const key of Object.keys(queryParams)) {
				if (key !== "pageNum" && key !== "pageSize") {
					if (Array.isArray(queryParams[key])) {
						if (queryParams[key].length) {
							this.isSearch = true;
							break;
						}
					} else if (queryParams[key]) {
						this.isSearch = true;
						break;
					}
				}
			}
		}
		this.$mitt.on("update-exchangeAndRedemption", this.getList);
		// this.initData();
		let dictValue = await dictOne("days");
		console.log(dictValue, "dictValue");
		this.dictValue = dictValue.data.dictValue;
		this.currentTime = dictValue.currentTime;
		this.getList();
	},
	beforeDestroy() {
		this.$mitt.off("update-exchangeAndRedemption", this.getList);
		// window.localStorage.removeItem("user");
		// window.localStorage.removeItem("query");
	},
	methods: {
		timeChange(type, field, value) {
			console.log(type, field, value);
			if (type == 1) {//开始时间
				// this.query.field = value ? value.split(" ")[1] +""
			}
			else {
				this.query[field] = value ? value.split(" ")[0] + " 23:59:59" : ""
			}
			console.log(this.query);

		},
		//判断时间
		// compareDateDifference(startDateStr, endDateStr, n) {
		// 	console.log(startDateStr, endDateStr, n);
		// 	if (!startDateStr) {
		// 		return false;
		// 	}
		// 	// 将时间字符串转换为 Date 对象
		// 	const startDate = new Date(startDateStr);
		// 	const endDate = new Date(Number(endDateStr));

		// 	// 计算两个时间戳的差值（单位：毫秒）
		// 	const timeDifference = startDate - endDate;

		// 	// 将差值转换为天数
		// 	let daysDifference = Math.abs(timeDifference) / (1000 * 60 * 60 * 24);
		// 	if (timeDifference < 0) {
		// 		daysDifference = -daysDifference;
		// 	}
		// 	// 判断差值是否大于或小于 n 天
		// 	if (daysDifference >= 0) {
		// 		return true;
		// 	} else if (daysDifference < 0) {
		// 		return false;
		// 	}
		// },
		compareDateDifference(startDateStr, endDateStr, n) {
			if (!startDateStr) {
				return false;
			}

			// 1. 将参数1（年月日字符串）转换为 Date 对象
			const startDate = new Date(startDateStr);

			// 2. 将参数2（时间戳字符串）转换为 Number 再转 Date 对象
			const endDateTimestamp = Number(endDateStr);
			if (isNaN(endDateTimestamp)) {
				console.error("endDateStr 不是有效的时间戳字符串");
				return false;
			}
			const endDate = new Date(endDateTimestamp);
			const endTime = new Date(endDate.getFullYear() + "-" + (endDate.getMonth() + 1) + '-' + endDate.getDate());
			// 3. 计算两个时间的差值（单位：毫秒）
			const timeDifference = startDate - endTime; // 参数1 - 参数2
			// 4. 将差值转换为天数
			const daysDifference = timeDifference / (1000 * 60 * 60 * 24);
			console.log(daysDifference);

			// 5. 判断是否 >= n 天
			return daysDifference >= 0;
		},
		getQueryParams() {
			return {
				...this.query
			}
		},
		async getListCount() {

		},
		// 获取列表
		async getList() {
			try {
				this.loading = true;
				const res = await getvdataaudiexchangelist(this.getQueryParams());
				console.log("res", res);
				this.total = +res.total;
				this.tableData = res.rows;
				// getData("252").then(res => {
				// 	console.log(res.data.dictValue);
				// 	this.dictValue = res.data.dictValue;
				// })
			} finally {
				this.loading = false;
			}
		},
		// 查看
		handleCheckDetail(row) {
			console.log(row);
			this.$router.push(
				`/addAndEdit?type=info&id=${row.id}&manufactureId=${row.dataaudit.manufactureId}`,
			);
		},
		//上传凭证
		handleUpload(row) {
			console.log(row);
			this.$router.push(
				`/addAndEdit?type=upload&id=${row.id}&manufactureId=${row.dataaudit.manufactureId}`,
			);
		},
		handleReUpload(row) {
			console.log(row);
			this.$router.push(
				`/addAndEdit?type=reupload&id=${row.id}&manufactureId=${row.dataaudit.manufactureId}`,
			);
		},
		// 审核
		handleExamine(row) {
			this.$router.push(
				`/addAndEdit?type=examine&id=${row.id}`,
			);
		},
		//撤销		
		handleRevoke(row) {
			this.$confirm("撤销之后，订单状态将从“审核通过”切换到“待审核”，是否确定此操作?", "提示", {
				confirmButtonText: "确定撤销",
				cancelButtonText: "取消",
				type: "warning",
			})
				.then(() => {
					revokeById(row.id).then(res => {
						this.$modal.msgSuccess("撤销成功");
						this.getList();
					})
				})
				.catch(() => {

				})
		},

		// 搜索
		handleQuery() {
			this.isSearch = true;
			this.query.pageNum = 1;
			this.$cache.session.setJSON("data-exchangeAndRedemption-query", this.query);
			this.getList();
		},
		// 重置
		resetQuery() {
			this.isSearch = false;
			this.query = {
				auditCode: "",//审核编码
				manufactureId: [],//厂商品牌id
				dataCategory: [],//资料类型
				auditStatus: [],//资料审核状态	
				status: [],//兑换审核状态
				vinNumber: "",
				carOwnerName: "",
				paymentType: [],//打款方式：1银行转账 2抵扣车款 3其他
				lastChangeTimeBeginTime: "",	//最新变更时间---开始时间
				lastChangeTimeEndTime: "",//最新变更时间---结束时间
				beginTime: "",//开始时间
				endTime: "",//结束时间
				voucherTimeBeginTime: "",//凭证提交时间-开始时间
				voucherTimeEndTime: "",//凭证提交时间-结束时间
				lastVoucherTimeBeginTime: "",//最后一次凭证提交时间-开始时间
				lastVoucherTimeEndTime: "",//最后一次凭证提交时间-结束时间
				isUploadVoucher: [],//是否上传凭证
				lastExaminePassTimeBeginTime: "",//最后一次审核通过时间-开始时间
				lastExaminePassTimeEndTime: "",//最后一次审核通过时间-结束时间
				exchangeBeginTime: "",
				exchangeEndTime: "",
				pageNum: 1,
				pageSize: 10,
			}
			this.$refs.queryForm.resetFields();
			this.$cache.session.setJSON("data-exchangeAndRedemption-query", this.query);
			this.getList();
		},
		/**
		 * 导入返利数据
		 */
		handleChangeRebateData(data) {
			this.loading = true;
			this.btn = "扫描中...";
			const formData = new FormData();
			formData.append("file", data.file);
			importRebateData(formData)
				.then((res) => {
					this.loading = false;
					this.btn = "确 认";
					this.$message.success("上传成功");
					this.getList()
					this.importRebateDataShow = false;
				})
				.catch((err) => {
					this.loading = false;
					this.btn = "确 认";
					this.showErr = true;
					this.uploadMsg = err.msg;
				});
		},
		/**
		 * 返利数据
		 */
		beforeUploadRebateData(data) {
			const fileTemp = data;
			if (this.fileListRebateData.length) {
				this.fileListRebateData = [];
			}
			if (fileTemp) {
				// 校检文件类型
				if (this.fileType.length) {
					let fileExtension = "";
					if (fileTemp.name.lastIndexOf(".") > -1) {
						fileExtension = fileTemp.name.slice(
							fileTemp.name.lastIndexOf(".") + 1,
						);
					}
					const isTypeOk = this.fileType.some((type) => {
						if (fileTemp.type.indexOf(type) > -1) return true;
						if (fileExtension && fileExtension.indexOf(type) > -1) return true;
						return false;
					});
					if (!isTypeOk) {
						this.$message.error(
							`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`,
						);
						return false;
					}
				}
			}
		},
		// 关闭导入置换数据弹窗
		importDataAuditClose() {
			this.fileList = [];
			this.importDataAuditShow = false;
		},
		// 关闭导入返利数据弹窗
		importRebateDataUploadClose() {
			this.fileList = [];
			this.importRebateDataShow = false;
		},
		downloadDataAuditTemplate() { },
		/**
		 * 下载返利模版
		 */
		downloadRebateDataUploadTemplate() {
			exportRebateDataTemplate().then(res => {
				console.log(res);
				downloadFile("返利模版", res);
			})
		},
		handleChange(data) {
			this.loading = true;
			this.btn = "扫描中...";
			const formData = new FormData();
			formData.append("file", data.file);
			importDataAudit(formData)
				.then((res) => {
					this.loading = false;
					this.btn = "确 认";
					this.$message.success("上传成功");
					this.importShow = false;
				})
				.catch((err) => {
					this.loading = false;
					this.btn = "确 认";
					this.showErr = true;
					this.uploadMsg = err.msg;
				});
		},
		// 上传模板
		beforeUpload(data) {
			const fileTemp = data;
			if (this.fileList.length) {
				this.fileList = [];
			}
			if (fileTemp) {
				// 校检文件类型
				if (this.fileType.length) {
					let fileExtension = "";
					if (fileTemp.name.lastIndexOf(".") > -1) {
						fileExtension = fileTemp.name.slice(
							fileTemp.name.lastIndexOf(".") + 1,
						);
					}
					const isTypeOk = this.fileType.some((type) => {
						if (fileTemp.type.indexOf(type) > -1) return true;
						if (fileExtension && fileExtension.indexOf(type) > -1) return true;
						return false;
					});
					if (!isTypeOk) {
						this.$message.error(
							`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`,
						);
						return false;
					}
				}
			}
		},
	},
};
</script>

<style scoped lang="scss">
::v-deep .el-pagination {
	display: flex;
	align-items: center;
	left: 0;

	.el-pagination__sizes {
		margin-left: auto;
	}
}

.msg {
	white-space: pre-wrap;
}
</style>
